﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;

namespace IHISCETeim.BLL
{
    public class XZJobTrainController:BaseController
    {
        /// <summary>
        /// 获取所有需要岗位的培训部门
        /// </summary>
        /// <returns></returns>
        public static List<string> GetAllTrainDept()
        {
            string deptlist = "营业本部,营业部,市场部,售后服务部,配件部,生产本部,生产管理部,技术部,质量管理部,生产部管理,生产部工人,管理本部,财务部,风险管理部,IT部,行政部";
            List<string> retlist = new List<string>();
            char[] caSplit = new char[] { ',' };
            string[] deptlistS = deptlist.Split(caSplit);

            foreach (string itm in deptlistS)
            {
                retlist.Add(itm);
            }

            return retlist;
        }

        /// <summary>
        /// 获取所有的岗位信息
        /// </summary>
        /// <returns></returns>
        public static List<XZJobListInfo> GetAllXZJobList()
        {
            List<XZJobListInfo> list = DC.Get<List<XZJobListInfo>>(BaseController.XZJobTrainControllerGetAllXZJobListKey);
            if (list == null)
            {
                list = CBO.FillCollection<XZJobListInfo>(XZJobTrainDAL.GetAllXZJobList());
            }
            return list;
        }
        /// <summary>
        /// 根据部门名称获取此部门下所有的岗位信息,如果没有则获取null
        /// </summary>
        /// <param name="JobDept"></param>
        /// <returns></returns>
        public static List<XZJobListInfo> GetAllXZJobListByJobDept(string JobDept)
        {
            List<XZJobListInfo> listAll = GetAllXZJobList();
            try
            {
                return listAll.Where(e => e.JobDept.Trim().ToUpper() == JobDept.Trim().ToUpper()).ToList();
            }
            catch
            {
                return null;
            }

        }

        public static XZJobListInfo GetJobByJobId(int JobId)
        {
            List<XZJobListInfo> listAll = GetAllXZJobList();
            try
            {
                return listAll.First<XZJobListInfo>(e => e.JobId == JobId);
            }
            catch
            {
                return new XZJobListInfo();
            }
        }


        /// <summary>
        /// 添加岗位培内容
        /// </summary>
        public static bool AddXZJobTrain(int JobId,List<XZJobTrainInfo> list)
        {
            return XZJobTrainDAL.AddXZJobTrain(JobId, list);
        }
       
        /// <summary>
        /// 获取岗位对应的所有培训内容
        /// </summary>
        /// <param name="JobId"></param>
        /// <returns></returns>
        public static List<XZJobTrainInfo> GetAllByJobId(int JobId)
        {
            return CBO.FillCollection<XZJobTrainInfo>(XZJobTrainDAL.GetAllByJobId(JobId));
        }
        /// <summary>
        /// 获取岗位对应的所有培训内容,用于导出
        /// </summary>
        /// <param name="JobId"></param>
        /// <returns></returns>
        public static DataTable GetAllByJobId2(int JobId)
        {
            return XZJobTrainDAL.GetAllByJobId2(JobId);
        }

        /// <summary>
        /// 添加培训内容清单
        /// </summary>
        /// <param name="TrainDept"></param>
        /// <param name="TrainContent"></param>
        /// <param name="ClassHour"></param>
        /// <param name="Unit"></param>
        /// <param name="ShowIndex"></param>
        /// <returns></returns>
        public static int AddXZTrainList(XZTrainListInfo obj)
        {
            return XZJobTrainDAL.AddXZTrainList(obj);
        }
        /// <summary>
        /// 删除培训内容清单
        /// </summary>
        /// <param name="TrainId"></param>
        /// <returns></returns>
        public static bool DeleteXZTrainList(int TrainId)
        {
            return XZJobTrainDAL.DeleteXZTrainList(TrainId);
        }
        /// <summary>
        /// 根据条件获取培训内容清单
        /// </summary>
        /// <param name="sqlwhere"></param>
        /// <returns></returns>
        public static List<XZTrainListInfo> GetAllXZTrainList(string sqlwhere)
        {
            return CBO.FillCollection<XZTrainListInfo>(XZJobTrainDAL.GetAllXZTrainList(sqlwhere));
        }
        /// <summary>
        /// 根据ID单个获取培训内容清单
        /// </summary>
        /// <param name="TrainId"></param>
        /// <returns></returns>
        public static XZTrainListInfo GetXZTrainById(int TrainId)
        {
            return CBO.FillObject<XZTrainListInfo>(XZJobTrainDAL.GetXZTrainById(TrainId));
        }
        /// <summary>
        /// 更新培训内容清单
        /// </summary>
        public static bool UpdateXZTrainList(XZTrainListInfo obj)
        {
            return XZJobTrainDAL.UpdateXZTrainList(obj);
        }
        /// <summary>
        /// 获取所有有培训内容的部门名称
        /// </summary>
        /// <returns></returns>
        public static DataTable XZTrainList_GetAllDept()
        {
            return XZJobTrainDAL.XZTrainList_GetAllDept();
        }
    }
}
